package com.webapp.dao;


import java.util.List;

import org.springframework.stereotype.Repository;

import com.webapp.helper.BaseDao;
import com.webapp.helper.OrderFilter.OrderType;
import com.webapp.helper.QueryParam;
import com.webapp.model.UserInfo;

@Repository
public class UserInfoDao extends BaseDao<UserInfo>{

	public UserInfo findByOpenid(String openid, Integer type){
		QueryParam param = QueryParam.getInstance();
		param.addParam("openid", openid);
		if(type!=null) {
			param.addParam("type", type);
		}
		param.addOrder(OrderType.DESC, "createTime");
		List<UserInfo>  list = findByCriteria(param);
		if(list!=null&&!list.isEmpty()) {
			return list.get(0);
		}
		return null;
	}
	
	public UserInfo findBySAndOAndC(String openid,String cph,String streetNo,Integer type) {
		QueryParam param = QueryParam.getInstance();
		param.addParam("openid", openid);
		param.addParam("cph", cph);
		if(type!=null) {
			param.addParam("type", type);
		}
		param.addParam("streetNo", streetNo);
		param.addOrder(OrderType.DESC, "id");
		return findByCriteriaForUnique(param);
	}
	
}
